package com.niiwoo.civet.trade.dao.mapper;

import com.niiwoo.civet.trade.dao.entity.CreditorSaleDetail;
import com.niiwoo.civet.trade.dto.request.creditor.CreditorSaleOrderPageRequestDTO;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

public interface CreditorSaleDetailMapperExt extends CreditorSaleDetailMapper {

	CreditorSaleDetail selectByPrimaryKeyAndSaleUserId(@Param("id") Long id,@Param("saleUserId") String saleUserId);

    List<CreditorSaleDetail> getCreditorSaleDetailOrderByBatchId(@Param("userId") String userId, @Param("creditorSaleBatchId") Long creditorSaleBatchId);

    List<CreditorSaleDetail> queryCreditorSaleDetailByAccountingStatusJob();

	List<CreditorSaleDetail> queryCreditorSaleDetailBySellerInvestPrizeStatusJob();

	List<CreditorSaleDetail> queryCreditorSaleDetailBySellerProjectActivityRaiseInterestStatusJob();

	List<CreditorSaleDetail> getUserCreditorSaleDetailOrderPage(CreditorSaleOrderPageRequestDTO request);
	
	CreditorSaleDetail selectByPrimaryKeyAndUserIdForUpdate(@Param("id") Long id, @Param("userId") String userId);
	
	List<CreditorSaleDetail> selectTimeoutToCancelled();
	
	Integer countInProgressOrderByUserIdAndInvestOrderId(@Param("userId") String userId, @Param("investOrderId") Long investOrderId);
	
	Integer getTradingCreditorSaleDetailNum(@Param("userId") String userId);
	
	/**
	 * 查询需要调用银行存管单笔债权出让补偿的债权记录
	 * 
	 * @return
	 */
	List<CreditorSaleDetail> selectNeedCompensationForDebentureSale();

	/**
	 * 查询需要调用银行存管取消债权出让补偿的债权记录
	 * 
	 * @return
	 */
	List<CreditorSaleDetail> selectNeedCompensationForCancelDebentureSale();

	/**
	 * 根据标的ID统计正在处理中（状态：出让申请中、出让中）债权订单数
	 *
	 * @param projectId
	 * @return
	 */
	List<CreditorSaleDetail>  selectInProgressOrderByProjectId(@Param("projectId") Long projectId);
	
	CreditorSaleDetail getAppliedSuccessfullyOrderByUserIdAndInvestOrderId(@Param("userId") String userId, @Param("investOrderId") Long investOrderId);
	
    int updateByPrimaryKeyAndUserIdSelective(CreditorSaleDetail record);
    
    List<CreditorSaleDetail> findUserUnderwayCreditorSaleDetail(@Param("userId") String userId,
			@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
}
